function [event_clock,alg]=produce(event_clock,alg)

global NUMBER_OF_EVENTS LENGTH BIG TNOW MAINT_COST REPAIR_COST SALES_REVENUE EXP_RATE 
global SHAPE1 SCALE1 SHAPE2 SCALE2 A3 B3 B U L MU STATES_MAX 
% A successful production has just been started 

% Since we have reached a new state, it is time to update Q-values*/

% Now to produce a state change, select an action


[action,alg]=action_selector_boltz(alg);

if 1==action 
% schedule a production cycle 

       
              
              prodtime=gamrnd(SHAPE2,SCALE2);
              if prodtime<alg.time_for_failure
              % production will occur successfully; schedule next production 
              
              alg.revenue=alg.revenue+SALES_REVENUE;
              
              alg.prodcount=alg.prodcount+1;
              alg.time_for_failure=alg.time_for_failure-prodtime;
              [alg]=rac(alg); 
              alg.old_action=1;
              alg.old_prodcount=alg.prodcount;
              event_clock(2)=TNOW+prodtime;
              else
              % schedule a repair 
              repair_time=unifrnd(A3,B3);
              event_clock(3)=TNOW+alg.time_for_failure+repair_time;
              event_clock(2)=BIG;       
              end
            

else
% schedule a maintenance */
maint_time=unifrnd(L,U);
event_clock(4)=TNOW+maint_time;
event_clock(2)=BIG;


end





